﻿using System.Diagnostics;
using HK.Core.Logs;
using HLogLevel = HK.Core.Logs.Protocol.LogLevel;

namespace HK.Editor.Extend
{
    /// <summary>
    /// 扩展类 : Editor
    /// </summary>
    public static class EditorEx
    {
        /// <summary>
        /// 信息日志(默认：运行日志).
        /// </summary>
        /// <param name="iEditor">Editor.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        [Conditional("HK_LOG_INFO")]
        public static void Info(this UnityEditor.Editor iEditor, string iFormat, params object[] iArgs) {
            if (Logger.LogLevel > HLogLevel.RInfo) {
                return;
            }
            var log = string.Format(iFormat, iArgs);
            Logger.Info($"[{iEditor.GetType().Name}] {log}");
        }

        /// <summary>
        /// 警告日志.
        /// </summary>
        /// <param name="iEditor">Editor.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        [Conditional("HK_LOG_WARNING")]
        public static void Warning(this UnityEditor.Editor iEditor, string iFormat, params object[] iArgs) {
            if (Logger.LogLevel > HLogLevel.Warning) {
                return;
            }
            var log = string.Format(iFormat, iArgs);
            Logger.Warning ($"[{iEditor.GetType().Name}] {log}");
        }

        /// <summary>
        /// 信息:逻辑(LI).
        /// </summary>
        /// <param name="iEditor">Editor.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        [Conditional("HK_LOG_INFO")]
        public static void LInfo(this UnityEditor.Editor iEditor, string iFormat, params object[] iArgs) {
            if (Logger.LogLevel > HLogLevel.LInfo) {
                return;
            }
            var log = string.Format(iFormat, iArgs);
            Logger.LInfo ($"[{iEditor.GetType().Name}] {log}");
        }

        /// <summary>
        /// 错误日志.
        /// </summary>
        /// <param name="iEditor">Editor.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        public static void Error(this UnityEditor.Editor iEditor, string iFormat, params object[] iArgs) {
            if (Logger.LogLevel > HLogLevel.Error) {
                return;
            }
            var log = string.Format(iFormat, iArgs);
            Logger.Error ($"[{iEditor.GetType().Name}] {log}");
        }

        /// <summary>
        /// 致命日志.
        /// </summary>
        /// <param name="iEditor">Editor.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        public static void Fatal(this UnityEditor.Editor iEditor, string iFormat, params object[] iArgs) {
            if (Logger.LogLevel > HLogLevel.Fatal) {
                return;
            }
            var log = string.Format(iFormat, iArgs);
            Logger.Fatal ($"[{iEditor.GetType().Name}] {log}");
        }
        
    }
}
